<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/1 0001
 * Time: 10:41
 */
namespace app\index\controller;
use think\Db;
use think\Request;

class Luck
{
    /**加载抽奖奖品数据
     * @param Request $request
     * @return \think\response\View
     */
    public function show_add(Request $request){
        return view('form/add_luck');
    }

    /**添加抽奖奖品
     * @param Request $request
     * @return int|string
     */
    public function add(Request $request){
        $data = $request->param();
        $seul = Db::connect();
        $shu = $seul->name('luck_draw')->count();
        if($shu>=8){
            return '选项已经添加完了,请修改或删除选项';
        }
        if($seul->name('luck_draw')->insert($data)){
            return 1;
        }else{
            return '请全部填上信息';
        }
    }
    public function update(Request $request){
        $id = $request->param('id',null);
        $prize_name = $request->param('prize_name',null);
        $Lottery_probability = $request->param('Lottery_probability',null);
        if(!$id||!$prize_name||!$Lottery_probability){
            return '参数有误';
        }
        if(Db::name('luck_draw')->where('id',$id)->update(['prize_name'=>$prize_name,'Lottery_probability'=>$Lottery_probability])){
            return 1;
        }else{
            return '你什么都没改变';
        }
    }
}